function [spec] = stft(signal, window, hop)

if(mod(window, hop) ~= 0)
    error('O tamanho de window deve ser multiplo de hop.');
end


Fs = 44100;
len = length(signal);                   % Tamanho do sinal
ham = hamming(window);                  % Janela de Hamming de tamanho window
num_quadros = (len-window)/hop;         % Numero de quadros do sinal
half = floor(window/2);                 % Metade do tamanho da janela
NFFT = 2^15;

T = 1/Fs;                     % Sample time
L = length(signal);                     % Length of signal
t = (0:L-1)*T;                % Time vector

L = (floor(L/hop)*256);

spec= zeros(NFFT/2,(L/hop) - floor( (window/hop) - 1 ));

for i=1:( (L/hop) - floor( (window/hop) - 1 ) )
    
    Y= fft(signal((i-1)*hop+1:((i-1)*hop +1)+window) ,NFFT)/ window;
    f = Fs/2*linspace(0,1,NFFT/2);
    spec (1:NFFT/2,i) = 2*abs(Y(1:NFFT/2));

end

